# STAT 202 Project
# Naive Bayes Classifier
# Author: Fatih Sunor
#####################################################

# Read data
rm(list = ls(all = TRUE));
train <- read.csv("training.csv",header=TRUE);
feature <- c(train[6:7], log(sqrt(train[9]*train[10])+1), train[11]);
relevance <- as.factor(train[[13]]);

# Naive Bayes
temp<-data.frame(relevance,feature);
model<-naiveBayes(relevance~.,data=temp,laplace = 5); 
p<-predict(model, feature);

# Test
sum(relevance!=p)/length(relevance);